package com.dacd.soundanalysis.soundhelper

/**
 *  复数
 */
class Complex() {

    var real: Double = 0.0
    var imagine: Double = 0.0

    constructor(real: Double, imagine: Double) : this() {
        this.real = real
        this.imagine = imagine
    }

    override fun toString(): String {
        return "Complex{real=$real,imagine=$imagine}"
    }

    /**
     * 加法
     */
    fun plus(other: Complex): Complex {
        return Complex(real + other.real, imagine + other.imagine)
    }

    /**
     * 乘法
     */
    fun multiple(other: Complex): Complex {
        return Complex(real * other.real - imagine * other.imagine, real * other.imagine + imagine * other.real)
    }

    /**
     * 减法
     */
    fun minus(other:Complex): Complex {
        return Complex(real - other.real, imagine - other.imagine)
    }

    /**
     * 求模
     */
    fun getMod(): Double {
        return Math.sqrt(real * real + imagine * imagine)
    }
}